import * as utils from "@/common/js/utils.js";
import cache from "@/common/js/cache";
const install = (Vue, vm) => {
	const sys = uni.getSystemInfoSync();
	const getDevicePlatform = () => {
		// #ifndef MP
		// #ifdef H5
		let ua = navigator.userAgent;
		// #endif
		// #ifdef APP-PLUS
		let ua = plus.navigator.getUserAgent()
		// #endif
		let isWindowsPhone = /(?:Windows Phone)/.test(ua);
		let isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone;
		let isAndroid = /(?:Android)/.test(ua);
		let isFireFox = /(?:Firefox)/.test(ua);
		let isChrome = /(?:Chrome|CriOS)/.test(ua);
		let isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox &&
			/(?:Tablet)/.test(ua));
		let isPhone = /(?:iPhone)/.test(ua) && !isTablet;
		let isPc = !isPhone && !isAndroid && !isSymbian;

		return {
			isTablet: isTablet,
			isPhone: isPhone,
			isAndroid: isAndroid,
			isPc: isPc
		};
		// #endif

		// #ifdef MP
		return {
			isPhone: sys.osName == 'ios',
			isAndroid: sys.osName == 'android',
			isTablet: sys.model == 'iPad',
		}
		//#endif
	}

	Vue.prototype.$k = {
		...utils.objFlat(utils.getModuleProps(require.context('./modules', false, /\.js$/), 'js')),
		...utils,
		cache,
		sys,
		device: getDevicePlatform()
	}

}

export default {
	install
}